package com.njiandan.johnson.vr360library.textures;

import android.content.Context;
import android.graphics.Bitmap;
import android.opengl.GLES20;

import com.njiandan.johnson.vr360library.utils.BitmapUtils;
import com.njiandan.johnson.vr360library.utils.TextureUtils;

/**
 * author：johnsonZhang on 2017/3/21 15:15
 * email：15915356@qq.com
 */
public class BitmapTexture {
    private int imageTextureId;
    private int imageSize[];

    public BitmapTexture() {
        this.imageSize = new int[2];
    }

    public BitmapTexture load(Context context, String filePath) {
        return loadBitmap(BitmapUtils.loadBitmapFromAssets(context, filePath));
    }

    public BitmapTexture loadBitmap(Bitmap bitmap) {
        this.imageTextureId = TextureUtils.getTextureFromBitmap(bitmap, this.imageSize);
        return this;
    }

    public int getImageTextureId() {
        return this.imageTextureId;
    }

    public int getImageWidth() {
        return this.imageSize[0];
    }

    public int getImageHeight() {
        return this.imageSize[1];
    }

    public void destory() {
        GLES20.glDeleteTextures(1, new int[]{this.imageTextureId}, 0);
    }
}
